﻿/// <reference path="JQuery/jquery-1.6.2-vsdoc.js" />
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//  Copyright(c)    2012    @kaleyroy   kaleyroy@gmail.com
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

/***********************
//  全局变量
************************/
var success = "success"; //成功标识
var error = "error";     //错误标识
var deny = "deny";       //否定标识
var invalid = "invalid"; //无效标识

/***********************
//  全局函数
************************/
/** 是否返回成功标识 **/
function isSuccess(o) {
    return o.Result == success;
}

/** 是否返回失败标识 **/
function isError(o){
    return o.Result == error;
}

/** 是否返回无效标识 **/
function isInvalid(o) {
    return o.Result == invalid;
}

/***********************
//  Ajax全局
************************/
/** Ajax请求开始 **/
$(document).ajaxStart(function () {
    $.mask({maskMsg:"正在处理,请稍候..."});
});

/** Ajax请求结束 **/
$(document).ajaxStop(function () {
    $.mask.hide();
});

/** Ajax请求成功 **/
$(document).ajaxSuccess(function() {
    //TODO
});

/** Ajax请求失败 **/
$(document).ajaxError(function(event, request, settings) {
    $.gritter.add({
        title: "请求响应异常",
        text: "<span style='font-weight:bold;color:yellow;'>非常抱歉,您发送的请求响应异常啦!</span>",
        time: "5000",
        image: "../Content/Images/error.png"
    });
});

/***********************
//  Gritter全局
************************/
/** Gritter消息 **/
function gritter(title, text, flag) {
    var timeout = "";
    var icon = "";
    var message = "";
    if (flag == success) {
        timeout = "1000";
        icon = "../Content/Images/accept.png";
        message = "<span style='font-weight:bold;'>" + text + "!</span>";
    } else if (flag == error) {
        timeout = "3000";
        icon = "../Content/Images/warning.png";
        message = "<span style='font-weight:bold;color:yellow;'>" + text + "!</span>";
    }
    $.gritter.add({
        title: title,
        text: message,
        time: timeout,
        image:icon
    });
}

/***********************
//  BlockUI全局
************************/
//默认加载消息遮罩样式*/
var defaultLoadingCss = {
    border: "none",
    padding: '15px',
    backgroundColor: '#000',
    '-webkit-border-radius': '10px',
    '-moz-border-radius': '10px',
    opacity: .5,
    color: '#fff'
}

/*默认加载消息内容*/
function defaultLoadingTip(msg){
    return "<h1><img src='../../Content/Images/loading.gif' /> " + msg + "...</h1>";
}

/*默认加载消息遮罩层*/
function loading(msg) {
    $.blockUI({
        message: "<h1><img src='../../Content/Images/loading.gif' /> " + msg + "...</h1>",
        css: {
            border: "none",
            padding: '15px',
            backgroundColor: '#000',
            '-webkit-border-radius': '10px',
            '-moz-border-radius': '10px',
            opacity: .5,
            color: '#fff'
        }
    });
}

/***********************
//  JSON时间格式化
//  依赖date.format.js
************************/
/** 日期形式 **/
function formatJSONDate(jsonDate) {
    var date = new Date(parseInt(jsonDate.substr(6)));
    return dateFormat(date, "isoDate");
}

/** 日期时间形式 **/
function formatJSONDateTime(jsonDate) {
    var date = new Date(parseInt(jsonDate.substr(6)));
    return dateFormat(date, "isoDateTime");
}

/***********************
//  文档加载(全局)
************************/
$(function () {

    /** 本地化设置 **/
    //$.linguaInit("../Scripts/Global/", "global");
    //$.linguaLoad("en-US");
});
